package com.xiaoerkeji.eshop.ui.dialog;


import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.xiaoerkeji.eshop.R;
import com.xiaoerkeji.eshop.databinding.DialogProgressBinding;
import com.lt.base.BaseDialog;
import com.lt.view.ViewHelper;

import java.util.Objects;


public class DialogProgress extends BaseDialog {
    private DialogProgressBinding binding;
    Animation mAnimation;

    public DialogProgress(Activity act) {
        super(act, R.style.dialog_no_border);
        this.mActivity = act;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(true);
        setCancelable(true);
        binding = DialogProgressBinding.inflate(getLayoutInflater());
        Objects.requireNonNull(getWindow()).setContentView(binding.getRoot());
        // 加载动画
        mAnimation = AnimationUtils.loadAnimation(mActivity,
                R.anim.load_animation);
        setOnDismissListener(dialogInterface -> {
            binding.img.clearAnimation();
        });
    }

    public DialogProgress show(Object message) {
        if (showDialog()) {
            // 使用ImageView显示动画
            binding.img.startAnimation(mAnimation);
            ViewHelper.getInstance().setTextView(binding.tv, message);
        }
        return this;
    }

    public TextView getTv() {
        return binding.tv;
    }
}
